package com.wsg.lightaccounting.PopupWindow;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.wsg.lightaccounting.Activity.CustomzedActivity;
import com.wsg.lightaccounting.Adapter.AccountBookListAdapter;
import com.wsg.lightaccounting.Adapter.ColorGridViewAdapter;
import com.wsg.lightaccounting.Fragment.RecordFragment;
import com.wsg.lightaccounting.Model.AccountManager;
import com.wsg.lightaccounting.Model.RecordManager;
import com.wsg.lightaccounting.R;

/**
 * Created by dell-pc on 2016/11/22.
 */

public class ColorChoosePopupWindow  extends PopupWindow{
    private GridView gridView;
    private Context context;
    private View mMenuView;
    private int i;

    public ColorChoosePopupWindow(final Context context, int w, int h, final ImageView imageView){
        super(context);
        this.context = context;
        LayoutInflater inflater = LayoutInflater.from(this.context);
        mMenuView = inflater.inflate(R.layout.color_popupwindow, null);
        gridView = (GridView) mMenuView.findViewById(R.id.color_grid);
        //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        gridView.setAdapter(new ColorGridViewAdapter(context));
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                AccountManager.setAccountColor(context,imageView,position);
                CustomzedActivity.color = position;
                dismiss();
            }
        });
        this.setWidth(w);
        this.setHeight(h);
        this.setAnimationStyle(R.style.popwin_anim_style);
        this.setFocusable(true);
        mMenuView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                int height = mMenuView.findViewById(R.id.layout).getTop();
                int y=(int) event.getY();
                if(event.getAction()==MotionEvent.ACTION_UP){
                    if(y<height){
                        dismiss();
                    }
                }
                return true;
            }
        });
    }
}
